﻿namespace System
{
  public class WsDataMsg : IMessage
  {
    public WsDataMsg(bool isBinary, string data, byte[] rawData)
    {
      this.IsBinary = isBinary;
      this.Data = data;
      this.RawData = rawData;
    }

    public string Data { get; }

    /// <summary>
    /// 是否是二进制数据。
    /// </summary>
    public bool IsBinary { get; }

    public byte[] RawData { get; }

    /// <summary>
    /// 获取可展示的数据内容。（二进制显示Hex，文本直接显示）
    /// </summary>
    /// <returns></returns>
    private string DisplayData()
    {
      if (IsBinary)
      {
        return BitConverter.ToString(RawData);
      }
      else
      {
        return Data;
      }
    }

    public override string ToString()
    {
      return $"{DateTime.Now.ToString("HH:mm:ss.fff")} {nameof(WsDataMsg)} {DisplayData()}";
    }
  }
}